/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package escr.clases;

/**
 *
 * @author Aditardo
 */
/*
 * IncrementoCodigos.java
 *
 * Created on 29 de junio de 2007, 12:29 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import escr.persistencia.Documento;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author USER_2007
 */
public class IncrementoCodigos {

    private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("WebAdtafa_EcPU");
    
    /** Creates a new instance of IncrementoCodigos */
    public IncrementoCodigos() {
    }
 
    public Integer incrementaUsuario() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.usrCodigo) FROM Usuario e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
     public Integer incrementaControlPresupuesto() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.cprId) FROM ControlPresupuesto e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
     
       
     public Integer incrementaNumControl() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.idnumCon) FROM Numcontrolpres e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
     
    
     public Integer incrementaNumIndicador() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.idnumIndicador) FROM Numindicador e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
     
     public Integer incrementaNumMenus() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.idnumMenu) FROM Nummenu e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
     
     public Integer incrementaNumDatos() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.idnumDatos) FROM Numdatos e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
     
     
    public Integer incrementaFiltro() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.filtinId) FROM Filtroindicicador e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaMenu() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.idMenu) FROM Menu e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
     public Integer incrementaRespuesPobla() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.dreCod) FROM DatospoblaRespuesta e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
     
     public Integer incrementaRespuesIndicador() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.resCod) FROM IndicaRespuestas e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    public Integer incrementaFiltroPobla() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.filpoId) FROM Filtropoblacion e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
   
     public Integer incrementaCuestionario() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.filtinNcuestia) FROM Filtroindicicador e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
     
     
      public Integer incrementaCuestPobla() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.filpoCuestio) FROM Filtropoblacion e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
      
    public Integer incrementaUsuarioTurno() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.ustCodigo) FROM Usuturno e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
public Documento datoPresu() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.docCod) FROM Documento e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Documento) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaAuditoria() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.audCodigo) FROM Auditoria e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
     
    public Integer incrementatipoUsuario() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.tpuCodigo) FROM TipoUsuario e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaDiagnostico() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.dgnCod) FROM Diagnostico e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaTipoEmpleado() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.temCodigo) FROM TiploEmpleado e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
 public Integer incrementaEmpleado() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.empCodigo) FROM Empleado e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
 public Integer incrementaTurno() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.turCodigo) FROM Turno e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
 
 
public Integer incrementaPaciente() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.pacCodigo) FROM Paciente e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }

public Integer incrementatipoPrograma() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.prgCod) FROM TipoPrograma e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }

public Integer incrementaEspecialidad () {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.espCod) FROM Especialidad e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }


public Integer incrementaProEspe () {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.preCod) FROM ProEspe e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }

public Integer incrementaProfesional() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.proCodigo) FROM Profesional e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }

public Integer incrementaPresupuesto() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.preCod) FROM Presupuesto e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }


 
 
    public Integer incrementaDocumento() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.docCod) FROM Documento e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }

    public Integer incrementaFinanciador() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.finCod) FROM Financiador e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }

    public Integer incrementaTipoFinanciador() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.tipCod) FROM TipoFinanciador e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }


    public Integer incrementaHorario() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.horId) FROM Horario e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    
    public Integer incrementaTipoPartida() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.tpaCod) FROM TipoPartida e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaPartida() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.parCodigo) FROM Partida e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaAreaIndic() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.areCod) FROM AreaIndic e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaIndicaRespuestas() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.resCod) FROM IndicaRespuestas e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaIndicadorPregunta() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.indCod) FROM IndicadorPregunta e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaTipoPoblacion() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.tpbCod) FROM TipoPoblacion e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaDatospoblaPregunta() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.dpbCod) FROM DatospoblaPregunta e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public Integer incrementaDatospoblaRespuesta() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();        
        Object u=null;
        try {
            // TODO:
             u = em.createQuery("SELECT max(e.dreCod) FROM DatospoblaRespuesta e").getSingleResult();    
          if (u==null) {
                 return null;
          }   
          return (Integer) u;
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
        return null;
    }
    
    public void persist(Object object) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            // TODO:
            // em.persist(object);    em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }

}
